package com.liang.maogouyuyin.ui.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.liang.maogouyuyin.bean.ArticleBean
import com.liang.maogouyuyin.bean.VarietyBean
import com.liang.maogouyuyin.network.RemoteRepository
import kotlinx.coroutines.launch

class PetMenuViewModel: ViewModel() {

    private val _catVarietyList = MutableLiveData<ArrayList<VarietyBean>>()
    val catVarietyList get() = _catVarietyList

    private val _dogVarietyList = MutableLiveData<ArrayList<VarietyBean>>()
    val dogVarietyList get() = _dogVarietyList

    private val _varietyDetail = MutableLiveData<String>()
    val varietyDetail get() = _varietyDetail

    private val _trainingList = MutableLiveData<ArrayList<ArticleBean>>()
    val trainingList get() = _trainingList

    private val _trainingArticle = MutableLiveData<String>()
    val trainingArticle get() = _trainingArticle

    private val _animalList = MutableLiveData<ArrayList<ArticleBean>>()
    val animalList get() = _animalList

    private val _animalArticle = MutableLiveData<String>()
    val animalArticle get() = _animalArticle

    fun getCatVariety() {
        viewModelScope.launch {
            _catVarietyList.value = RemoteRepository.getCatVariety()
        }
    }

    fun getDogVariety() {
        viewModelScope.launch {
            _dogVarietyList.value = RemoteRepository.getDogVariety()
        }
    }

    fun getVarietyDetail(url: String) {
        viewModelScope.launch {
            _varietyDetail.value = RemoteRepository.getVarietyDetail(url)
        }
    }

    fun getTrainingList() {
        viewModelScope.launch {
            _trainingList.value = RemoteRepository.getTraining()
        }
    }

    fun getTrainingArticle(url: String) {
        viewModelScope.launch {
            _trainingArticle.value = RemoteRepository.getTrainingArticle(url)
        }
    }

    fun getAnimalList() {
        viewModelScope.launch {
            _animalList.value = RemoteRepository.getAnimal()
        }
    }

    fun getAnimalArticle(url: String) {
        viewModelScope.launch {
            _animalArticle.value = RemoteRepository.getAnimalArticle(url)
        }
    }
}